class Queue {
    constructor(x) {
        this.x = x;
        this.array = new Array(x)
        this.front = 0
        this.rear = 0
    }
    enQueue(element) {
        if ((this.rear + 1) % this.array.length === this.front) {
            throw new Error('队列已满')
        }
        this.array[this.rear] = element
        this.rear = (this.rear + 1) % this.array.length
    }
    deQueue() {
        if (this.rear === this.front) {
            throw new Error('队列已空')
        }
        this.front = (this.front + 1) % this.array.length;
    }
    output() {
        for (let i = this.front; i != this.rear; i = (i + 1) % this.array.length) {
            console.log(this.array[i])
        }
    }
}
let queue = new Queue(6)
queue.enQueue(3);
queue.enQueue(5);
queue.enQueue(6);
queue.enQueue(8);
queue.enQueue(1);
queue.deQueue();
queue.deQueue();
queue.deQueue();
queue.deQueue();
queue.enQueue(2);
queue.enQueue(4);
queue.enQueue(9);
queue.output();
console.log(queue)